//
//  BaseController.swift
//  SinaWeibo
//
//  Created by apple on 15/11/8.
//  Copyright © 2015年 apple. All rights reserved.
//

import UIKit

//遵守协议 类似于多继承 必须实现方法
class BaseController: UITableViewController ,VisitorLoginViewDelegate{
    
    
    //判断用巨是否登录
    var userLogin = UserAccountViewModel().userLogin
  
    var visitorLoginView:VisitorLoginView?
    
    //loadView 这个方法是苹果专门为手吗创建而生的 会自动判断是否为空
        
        override func loadView() {
            
            userLogin ? super.loadView() : loadVisitorView()
        }

    
    func loadVisitorView() {
        
        visitorLoginView = VisitorLoginView()
        
        visitorLoginView?.visitordelegate = self
        
        view = visitorLoginView
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "visitorLogin")
        
         self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorRegister")
    }
    
    //实现代理方法
    func visitorLogin() {
        
        let vc = OauthViewController()
        
       let nav = UINavigationController(rootViewController: vc)
        
        self.navigationController?.presentViewController(nav, animated: true, completion: nil)
    }
    func visitorRegister() {
        
        print("come on")
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
}
